﻿#region License
/* ---------------------------------------------------------------- *
 *
 * This file is part of the Xcoordination Application Space
 * ("XcoAppSpace") http://www.xcoordination.com
 *
 * Copyright (C) 2009 Xcoordination http://www.xcoordination.com
 *
 * XcoAppSpace is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General
 * Public License as published by the Free Software Foundation.
 *
 * XcoAppSpace is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/
 * or write to the Free Software Foundation, Inc., 51 Franklin
 * Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * ---------------------------------------------------------------- */
#endregion

using Microsoft.Ccr.Core;
using System;
namespace XcoAppSpaces.Contracts.Messaging
{
	/// <summary>
	/// Provides information about a message to be sent.
	/// </summary>
    public class MessageToSend
	{
		/// <summary>
		/// The address of the space the message should be sent to.
		/// </summary>
		public string RemoteAddress { get; private set; }

		/// <summary>
		/// The name of the transport service that should be used to send the message.
		/// </summary>
		public string CommServiceName { get; private set; }

		/// <summary>
		/// The causality context of the message.
		/// </summary>
		public CausalityContext Context { get; private set; }

		/// <summary>
		/// The messsage to be sent.
		/// </summary>
		public RemoteMessage Data { get; private set; }

		/// <summary>
		/// Optional port for posting back communication errors. If this port is set, then not the causality
		/// will be used for communication errors, but this port. This is e.g. used when using Send() instead
		/// of Post().
		/// </summary>
		public Port<Exception> CommErrorPort { get; private set; }

		/// <summary>
		/// Optional port for posting back ack when the message has been successfullly sent. If this port 
		/// is set, then not the causality coordination port will be used for ack, but this port. This
		/// is e.g. used when using Send() instead of Post() to prevent the need of installing a causality
		/// just for the ACK functionality.
		/// </summary>
		public Port<Ack> CommAckPort { get; private set; }

		/// <summary>
		/// Creates a new MessageToSend.
		/// </summary>
		/// <param name="remoteAddress">The address of the space the message should be sent to.</param>
		/// <param name="commServiceName">The name of the transport service that should be used to send the message.</param>
		/// <param name="context">The causality context of the message.</param>
		/// <param name="data">The messsage to be sent.</param>
		/// <param name="commErrorPort">Optional port for communication errors.</param>
		/// <param name="commAckPort">Optional port for communication ACK.</param>
		public MessageToSend(string remoteAddress, string commServiceName, CausalityContext context, RemoteMessage data, Port<Exception> commErrorPort, Port<Ack> commAckPort)
		{
			this.RemoteAddress = remoteAddress;
			this.CommServiceName = commServiceName;
			this.Context = context;
			this.Data = data;
			this.CommErrorPort = commErrorPort;
			this.CommAckPort = commAckPort;
		}
	}
}
